/// Creator:      gaoruishan
/// CreatDate:    2025-09-01
/// Description:  患者交接节点
Class CF.NUR.MNISV3.PHONode Extends %Persistent
{

Relationship PHOType As CF.NUR.MNISV3.PHOType [ Cardinality = parent, Inverse = PHONode ];

/// 节点名称
Property NodeName As %String(TRUNCATE = 1);

/// 节点code
Property NodeCode As %String(TRUNCATE = 1);

/// 节点序号
Property NodeSort As %String(TRUNCATE = 1);

/// 安全组Id
Property GroupId As %String(TRUNCATE = 1);

/// 是否有效
Property ValidFlag As %String(TRUNCATE = 1);

/// 【必填】关联模板（ 多个用!分隔）-->对应模块 CF.NUR.MNISV3.ModelForm
Property PHOModel As %String(TRUNCATE = 1);

/// 索引
Index Code On NodeCode;

/// 保存
/// w ##class(CF.NUR.MNISV3.PHONode).Save("","PHOTypeId|1^NodeName|入手术室^NodeCode|RSSS^NodeSort|1^PHOModel|")
/// w ##class(CF.NUR.MNISV3.PHONode).Save("","PHOTypeId|1^NodeName|出手术室^NodeCode|CSSS^NodeSort|2^PHOModel|")
/// w ##class(CF.NUR.MNISV3.PHONode).Save("","PHOTypeId|2^NodeName|急诊转住院^NodeCode|JJZZY^NodeSort|1^PHOModel|")
/// w ##class(CF.NUR.MNISV3.PHONode).Save("","PHOTypeId|2^NodeName|转科^NodeCode|JJZZY^NodeSort|2^PHOModel|")
/// w ##class(CF.NUR.MNISV3.PHONode).Save("","PHOTypeId|2^NodeName|转院^NodeCode|ZY^NodeSort|3^PHOModel|")
ClassMethod Save(id, parr)
{
    s tmp=""
    s a=##class(web.DHCMGNurComm).setmoudtmp(parr,.tmp)
    s NodeCode=$zcvt(tmp("NodeCode"),"u")
    s typeId=$O(^CF.NUR.MNISV3.PHONodeI("Code"," "_NodeCode,""))
    i typeId'="" { // 父子表--ID有两层
        s rw=$O(^CF.NUR.MNISV3.PHONodeI("Code"," "_NodeCode,typeId,""))
        i rw'="" s id=typeId_"||"_rw //更新数据
    } 
    if id'=""
    {
        s rec=##class(CF.NUR.MNISV3.PHONode).%OpenId(id)
    }else{
        s rec=##class(CF.NUR.MNISV3.PHONode).%New()
        s rec.PHOType=##class(CF.NUR.MNISV3.PHOType).%OpenId(tmp("PHOTypeId"))
    }
    i $d(tmp("NodeName")) s rec.NodeName=tmp("NodeName")
    i $d(tmp("NodeCode")) s rec.NodeCode=tmp("NodeCode")
    i $d(tmp("NodeSort")) s rec.NodeSort=tmp("NodeSort")
    i $d(tmp("GroupId")) s rec.GroupId=tmp("GroupId")
    i $d(tmp("ValidFlag")) s rec.ValidFlag=tmp("ValidFlag")
    i $d(tmp("PHOModel")) s rec.PHOModel=tmp("PHOModel")
    s sc=rec.%Save()
    s id=rec.%Id()
    d rec.%Close()
    q:$$$ISERR(sc) "err:"_$SYSTEM.Status.GetErrorText(sc)
    q id
}

Storage Default
{
<Data name="PHONodeDefaultData">
<Value name="1">
<Value>%%CLASSNAME</Value>
</Value>
<Value name="2">
<Value>NodeName</Value>
</Value>
<Value name="3">
<Value>NodeCode</Value>
</Value>
<Value name="4">
<Value>NodeSort</Value>
</Value>
<Value name="5">
<Value>GroupId</Value>
</Value>
<Value name="6">
<Value>ValidFlag</Value>
</Value>
<Value name="7">
<Value>PHOModel</Value>
</Value>
</Data>
<DataLocation>^CF.NUR.MNISV3.PHONodeD</DataLocation>
<DefaultData>PHONodeDefaultData</DefaultData>
<IdLocation>^CF.NUR.MNISV3.PHONodeD</IdLocation>
<IndexLocation>^CF.NUR.MNISV3.PHONodeI</IndexLocation>
<StreamLocation>^CF.NUR.MNISV3.PHONodeS</StreamLocation>
<Type>%Storage.Persistent</Type>
}

}
